package cn.golxen.blog.controller;

import cn.golxen.blog.commons.utils.Result;
import cn.golxen.blog.commons.vo.CheckAdminVo;
import cn.golxen.blog.commons.vo.ResCheckAdminVo;
import cn.golxen.blog.exception.exceptionClass.UpdateAdminException;
import cn.golxen.blog.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping(value = "/admin")
public class AdminController {
    @Autowired
    AdminService adminService;

    @GetMapping(value = "/get/avatar")
    public Result getAvatar(){
        String avatar= adminService.getAvatar();
        return Result.successResult(avatar);
    }
    @GetMapping(value = "/get/signature")
    public Result getSignature(){
        String signature= adminService.getSignature();
        return Result.successResult(signature);
    }
    @GetMapping(value = "/get/resume")
    public Result getResume(){
        String resume=adminService.getResume();
        return Result.successResult(resume);
    }

    @PostMapping(value = "/update/avatar")
    public Result updateAvatar(@RequestBody String url){
        log.info("url:"+url);
        Integer integer=adminService.updateAvatar(url);
        if (integer!=0)
            return Result.successResult();
        else throw new UpdateAdminException();
    }

    @PostMapping(value = "/update/signature")
    public Result updateSignature(@RequestBody String signature){
        Integer integer=adminService.updateSignature(signature);
        if (integer!=0)
            return Result.successResult();
        else throw new UpdateAdminException();
    }

    @PostMapping(value = "/update/resume")
    public Result updateResume(@RequestBody String resume){
        Integer integer=adminService.updateResume(resume);
        if (integer!=0)
            return Result.successResult();
        else throw new UpdateAdminException();
    }

    @GetMapping(value = "/update/redis/flushDB")
    public Result flushDB(){
        adminService.flushDB();
        return Result.successResult();
    }

    @PostMapping(value = "/check")
    public Result checkAdmin(@RequestBody CheckAdminVo checkAdminVo){
        ResCheckAdminVo resCheckAdminVo= adminService.checkAdmin(checkAdminVo);
        return Result.successResult(resCheckAdminVo);
    }
}
